<template>

   <div class="app-container">
      医院设置添加 | 
      <el-form label-width="120px">
         <el-form-item label="医院名称">
            <el-input v-model="hospitalSet.hosname"/>
         </el-form-item>
         <el-form-item label="医院编号">
            <el-input v-model="hospitalSet.hoscode"/>
         </el-form-item>
         <el-form-item label="api基础路径">
            <el-input v-model="hospitalSet.apiUrl"/>
         </el-form-item>
         <el-form-item label="联系人姓名">
            <el-input v-model="hospitalSet.contactsName"/>
         </el-form-item>
         <el-form-item label="联系人手机">
            <el-input v-model="hospitalSet.contactsPhone"/>
         </el-form-item>
         <el-form-item>
            <el-button type="primary" @click="saveOrUpdate">保存</el-button>
         </el-form-item>
      </el-form>
   </div>
</template>

<script>
import hospset from "@/api/hospset";
export default {
    name:'add',
    data() {
        return {
            hospitalSet:{},
            // nowid:0
        }
    },
    created(){
      //再页面获取时，通过id
     //判断是否有id传入
     if(this.$route.params.id && this.$route.params){
          //获取路由中绑定得值 :id 
       const id= this.$route.params.id
        // this.nowid=id
        this.GetHospSet(id)
     }else{
         this.hospitalSet={}
     }
    },
    methods: {
        save(){
           hospset.savehospSet(this.hospitalSet)
           .then(re=>{
               //提示
               this.$message({
                  type: 'success',
                  message: '添加成功!'
               })
               //跳转列表页面，使用路由跳转方式实现
               this.$router.push({path:'/hospSet/list'})
           })
        },
        updata(){
            hospset.updateHospSet(this.hospitalSet)
           .then(re=>{
               //提示
               this.$message({
                  type: 'success',
                  message: '修改成功!'
               })
               //跳转列表页面，使用路由跳转方式实现
               this.$router.push({path:'/hospSet/list'})
           })
        },
        //通过id有无来实现是添加还是修改
        saveOrUpdate(){
            if(!this.hospitalSet.id){
                 this.save();
            }else{
                this.updata();
            }

        },
        //定义通过id获取得信息方法
        GetHospSet(id){
          hospset.getidhosp(id)
          .then(re=>{
              //获取re中得data及医院设置信息 ，并赋值给原data中得hospitalSet
              this.hospitalSet=re.data
          })
    }
    }
}
</script>

<style>

</style>